Part Number Hot Search : 
PZ3032 PZ3032 T101K PZ3032 T101K HIN238IB NT6812 LF353D
Product Description
Full Text Search
 

To Download AVR1300 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  AVR1300: using the atmel avr xmega adc features ? up to 12 bit resolution ? up to 2m samples per second ? signed and unsigned mode ? selectable gain ? pipelined architecture ? up to 4 virtual channels ? result comparator ? automatic calibration ? internal connection to dac output ? driver source code included 1 introduction the atmel ? avr ? xmega ? adc module is a high-performance analog-to-digital converter capable of conversion rates up to 2 million samples per second (msps) with a resolution of 12 bits. a wide range of multiplexer (mux) settings, integrated gain stage and four virtual input channels make this a flexible module suitable for a wide range of applications, such as data acquisition, embedded control and general signal processing. this application note describes the basi c functionality of the xmega adc with code examples to get up and running quickly. the examples are implemented in software framework (asf 2.0), which are available for the atmel avr xmega and atmel ? avr ? uc3 tm microcontroller series. advanced usage, such as direct memo ry access (dma) and the xmega event system, is outside the scope of this app lication note. please refer to the device datasheets and other relevant applicati on notes such as avr1304: using the xmega dma controller, and avr1001: getting started with the xmega event system. figure 1-1. adc overview 8-bit microcontrollers application note preliminary rev. 8032h-avr-12/10
2 AVR1300 8032h-avr-12/10 2 table of content AVR1300: using th e xmega adc ..................................................... 1 features ............................................................................................... 1 1 introduc tion ...................................................................................... 1 2 table of content ............................................................................... 2 3 module o verview ............................................................................. 4 3.1 pipeline architecture and virtual channels......................................................... 4 3.2 gain stage........................................................................................................... 6 3.3 conversi on mode ................................................................................................ 6 3.4 multiplexe r settings ............................................................................................. 7 3.4.1 differential i nput without gain .................................................................................... 8 3.4.2 differential input with gain stage .............................................................................. 9 3.4.3 single-e nded input .................................................................................................... 9 3.4.4 intern al i nput ........................................................................................................... 10 3.4.5 temperat ure sens or ................................................................................................ 11 3.5 conversi on result ............................................................................................. 12 3.5.1 sign ed mode ........................................................................................................... 12 3.5.2 unsign ed m ode ....................................................................................................... 12 3.6 result pr esentation ........................................................................................... 13 3.7 voltage re ferences........................................................................................... 13 3.8 conversion speed ............................................................................................. 14 3.9 free-runn ing m ode............................................................................................ 15 3.10 interr upts ......................................................................................................... 15 3.11 result compar ator inte rrupt............................................................................ 16 3.12 calibr ation ....................................................................................................... 16 3.12.1 offset error ............................................................................................................ 17 3.12.2 offset error ? si ngle-ended ch annels ..................................................................... 17 3.12.3 offset error - di fferential ch annels ......................................................................... 18 3.12.4 gain error .............................................................................................................. 18 3.12.5 non-li nearit y .......................................................................................................... 1 9 3.12.6 differential non-linear ity......................................................................................... 19 3.12.7 integral non-linearit y .............................................................................................. 20 3.12.8 measurements an d compensat ion ........................................................................ 20 3.12.9 deco upling ............................................................................................................ 20 3.12.10 source impedanc e............................................................................................... 21 3.13 tips for impr oving accuracy ............................................................................ 22 4 getting st arted ............................................................................... 23 4.1 single co nversion ............................................................................................. 23 4.2 multiple channels .............................................................................................. 23 4.3 free-runn ing m ode............................................................................................ 24
AVR1300 3 8032h-avr-12/10 5 advanced f eatures ........................................................................ 24 5.1 dma cont roller .................................................................................................. 24 5.2 event system .................................................................................................... 24 6 driver impl ementati on ................................................................... 25 6.1 file s ................................................................................................................... 25 6.2 doxygen docu mentation ................................................................................... 25 disclaimer................................................. error! bookmark not defined.
4 AVR1300 8032h-avr-12/10 3 module overview this section provides an overview of the functionality and basic configuration options of the adc. section 3 will walk you through the basic setup and usage of adc on regi ster level. 3.1 pipeline architecture and virtual channels the adc conversion block has a 12-stage pi pelined architecture capable of sampling several signals in parallel. there are four input selection multiplexers with individual configurations. the separate configuration settings for the four multiplexers can be viewed as virtual channels , with one set of result registers each, all sharing the same adc conversion block. refer to figure 1-1 page 1 on the atmel ? avr ? xmega ? a series the multiplexer outputs can be sampled every adc clock cycles. on the xmega d series a new measurement can be sampled once the previous conversion is done. each signal propagates through the pipeline, where one bit is converted at each stage. in this way the adc in the xmega a is capable of sampling one signal every adc clock cycle, even if each signal must propagate through all stages in the pipeline before the result is ready in the result register. the propagation time for one single signal conversion th rough the pipeline is 7 adc clock cycles for 12-bit conversions a nd 5 cycles for 8-bit conversions. if gain is used the propagation time increases by one cycle. at full utilization the xmega a adc delivers one result every adc clock cy cle while the xmega d adc delivers one sample every 5 ? 8 adc clock cycle dep ending on operating mode. the relation between the xmega peripheral clock and the adc clock is described in section 2.8 . figure 2-1 on page 5, shows a simplified 4-stage p ipeline during conversion of two input signals. the figure shows that once the signal has been sampled into the pipeline, the first stage converts the msb of the first signal. while the second stage is converting the next bit of the signal, the first stage now converts the msb of the second signal. note that the xmega d3/d4 families do not have a pipelined adc and 4 virtual channels pr. adc.
AVR1300 5 8032h-avr-12/10 figure 3-1. simplified adc pipeline with two propagating signals 3 3 2 1 0 3 2 1 0 2 3 3 3 2 1 0 2 3 3 2 3 2 1 0 2 3 3 2 1 1 0 1 3 2 1 0 3 2 1 0 result register 0 3 2 1 0 result register 1 3 2 1 0 1 2 3 4 5 channel 0 channel 1 all the four virtual channels have one mux control register ( chn.muxctrl ), one channel control register ( chn.ctrl ) and one result register pair ( chn.resl / chn.resh ) each, in addition to several control bits distributed in shared registers.
6 AVR1300 8032h-avr-12/10 3.2 gain stage the adc has an internal gain stage which c an be configured to amplify a voltage to allow measurement of smaller voltages in differential mode. this is a shared gain stage that can be us ed by all the channels. when the channel is configured to use gain, the gain stage is inserted between the channel input selection mux and the conversion block. the available gain settings are 1x, 2x, 4x, 8x, 16x, 32x and 64x. the atmel ? avr ? xmega ? d series can also do 1/2x gain (div2). the gain factor bit field ( gainfact ) in the channel control register ( chn.ctrl ) set the gain factor for the channel. it is possible to have individual gain settings for all the virtual channels. the propagation delay for an adc sample through the adc module increases by one adc clock cycle flat on the xmega a series when using the gain stage, on the xmega d series the propagation delay is depended of the gain setting. ? propagation delay = 1 for 1/2x, 1x, 2x and 4x gain settings ? propagation delay = 2 for 8x and 16x gain settings ? propagation delay = 3 for 32x and 64x gain settings to minimize the analog signal path for best possible adc result it is recommended to disable gain when not needed. 3.3 conversion mode the conversion block can be put in the unsigned or signed conversion mode. changing between unsigned/signed and single-ended/differential modes will corrupt data already in the pipeline. signed mode can be used as input mode for both differential and single-ended inputs, while unsigned mode is only available for the single-ended or internal input. in unsigned mode the conversion range is from ground to the reference voltage. to be able to have zero-cross detection a v is subtracted. the v is approximately 0.05*vref, so the ground level will be approximately 0.05 of the total value range (0.05 * 4095 with 12-bit resolution). this will also limit the maximum input voltage of 0.05*vref, so the maximum input voltage is vref - v. this is illustrated in figure 3-2. in signed mode the range is from negative to positive reference voltage, but the input voltage must be within gnd and vref. the figure below shows the difference in conversion ranges.
AVR1300 7 8032h-avr-12/10 figure 3-2. unsigned and signed conversion mode +v ref - v 4095 v inn +v ref 0 2047 v inn -v ref -2048 gnd approx. 200 input voltage digital result input voltage digital result unsigned mode signed mode the figure shows that the unsigned mode gives higher resolution on positive values than signed mode, but cannot convert negativ e values. the signed mode can convert negative values, but at the cost of lower resolution overall. note that negative values are not negative i nputs on the io pins, but higher voltage level on the negative input in respect to the positive input. even though the resulting value can be negative, voltages below gnd or above vcc should under no circumstances be applied to any input port. when the adc uses differential input, signed mode must be used, when using single- ended input both signed and unsigned mode can be used. note that conversion mode is configured fo r the whole adc, not individually for each channel, which means that the adc must be put in the signed mode even if only one of the channels uses differential inputs. the conversion mode is configured using the conversion mode bit ( convmode ) in control register b ( ctrlb) . 3.4 multiplexer settings the muxes are used to select input signal for each virtual channel. there are four different configuration choices that can be selected using the channel input mode bitfield ( inputmode ) in the channel control register ( chnctrl ): ? differential input without gain ? differential input with gain stage ? single-ended input ? internal input the positive and negative inputs are selected using the mux positive input and mux negative input bitfields ( muxpos and muxneg ) in the channel mux control register (muxctrl). an alternative name for the mux positive input bitfield used in the header files is mux internal input ( muxint ) when measuring internal inputs.
8 AVR1300 8032h-avr-12/10 in devices with two adcs, the inputs can only be connected to the corresponding port. meaning that adc a can only be connected to port a and adc b can only be connected to port b. the positive input can be connected to any one of the eight input signals of the corresponding port. t he negative input can be connected to one of the first four input signals (pin0 ? pin3) of the corresponding port for differential without gain and the second four input signals (pin4 ?pin7) for differential with gain. in devices with only one adc but severa l analog ports, the positive input can be connected to any of the available input signals from both port a and port b. the negative input can be connected to one of the first four input signals (pin0 ? pin3) of the corresponding port for differential without gain and the second four input signals (pin4 ?pin7) for differential with gain. refer to the datasheet to determine t he number of adcs and the devices pin configuration. note that the sampling capacitor is drained between each sample for all modes except for differential mode with gain. in t he differential mode with gain, the charge on the sampling capacitor is maintained and this can be used to get a higher sample rate on slow changing signals. this can be used to get higher sampling rates on high impedance sources compared to single channel or differential channel (without gain) sampling. this will however propagate to other channels if the sample rate is too high compared to the source impedance. 3.4.1 differential input without gain with this setting, the mux measures t he difference between two input signals. in differential mode without gain all adc inputs can be used for the positive input of the adc but only the lower 4 pins can be used as the negative input. when using differential mode, offset can be measured qu ite easily by setting up the positive and negative input on the same pin, and the offs et can be measure directly as the adc does not need to know where the ground level is. figure 3-3. differential input without gain stage pin inputs pipelined adc block pin inputs positive input negative input
AVR1300 9 8032h-avr-12/10 3.4.2 differential input with gain stage this setting is almost identical to differential input without gain stage. with this setting the gain stage is inserted in the signal path for this channel, providing up to 64 times amplification of the differential input signal. maximum sampling speed while using the gain stage is 1msps. figure 3-4. differential input with gain stage pin inputs pipelined adc block pin inputs positive input negative input gain note that the gain stage does not load the i nput, hence external signal sources will see very high input impedance for channels t hat use the gain stage. this is useful for measuring weak signal sources. more details can be found in the datasheet for the specific device. the voltage on any of the two inputs can be between gnd and v ref , but the difference between them must not be larger than v ref /gain because this will saturate the adc and the converted value will only equal the top value of the adc. 3.4.3 single-ended input with this setting, the adc measures the value of one input signal. the difference between this setting and differential measurement is that the negative input is always connected internally to a defined level depending on if signed or unsigned mode is being used. for signed mode the negative i nput is tied to gnd while in unsigned mode it is connected to vref/2 ? v. figure 3-5. single-ended input in signed mode v is a fixed internally generated voltage of approximately 0.05*vref. this offset needs to be measured by connecting the positive input to ground (gnd). the offset will typically correspond to a value of about 200 when measured.
10 AVR1300 8032h-avr-12/10 the advantage of v is that it will be possible to measure a negative offset in the adc block because v will be larger than any offset. v will allow the xmega adc to be used in applications where it is essential to know and compensate for offset errors. the disadvantage is that some of the upper range is lost since any measurement above vref ? v will saturate to the top value. in addition to connecting the negative input the adc will in unsigned single ended mode automatically add 2048 to the result. this gives a possible output range from 0 to 4096 as opposed to -2048 to 2047 for signed mode. figure 3-6. single-ended input in unsigned mode note: since the adc is differential, unsi gned mode is achieved by dividing the reference by two internally, resulting in an input range from vref to zero for the positive single ended input. the offset enables the adc to measure zero cross detection in unsigned mode, and to calibrate any positive offset where the internal ground in the device is higher than the external ground. 3.4.4 internal input with thi s setting, the mux measures one of several internal signals. the negative input is always connected to gnd while the positive input can be connected to one of the following internal sources: temperature reference, dac internal output, avcc/10 (for supply voltage measurement) or bandgap reference. note that two channels can select different internal sources. they are not limited to one common setting, as opposed to the shared gain stage setting. the internal dac input can be used for calibration of the dac. for more information about dac configuration, please refer to the device datasheet or the application note ?avr1301: getting started with the xmega dac?. the bandgap reference can be used as a reference to calculate the external reference, like a battery voltage, if the vo ltage is unknown. with a measurement of a known voltage (the bandgap reference, 1.1 v) using an unknown reference, it is easy to calculate the actual voltage of the external reference.
AVR1300 11 8032h-avr-12/10 figure 3-7. internal input in signed mode figure 3-8. internal input in unsigned mode note that if no other modules are using the bandgap reference. it must be turned on using the bandgap enable bit ( bandgap) in the reference control register ( refctrl ). the same goes for the temperature reference, which is not shared with any other modules. the temperature reference is turned on using the temperature reference enable bit ( tempref ). also note that there is a certain settling time for both bandgap and temperature reference, hence they should be enabled in due time before starting any conversions. note that maximum sampling speed of the internal inputs is 125ksps. 3.4.5 temperature sensor the inte rnal temperature sensor is linear . ideally the measured value at 0k will correspond to a ?0? result from the adc. an approximate linear line can be made from the 0k to the measured value in the production. this measured production value is stored in the signature row and the value correspond to a measurement done at 85c (358k) with an accu racy of +- 5c. the inaccuracy will result in some offset when measuring temperatures. the measurement stored in the signature row is done in unsigned mode with 12-bit resolution with the internal 1v reference. the adc setup has to be the same if this value is going to be used in the application. the stored value can be used for a 2- point calibration where the second point will be 0k and the adc value will be 0. the best way to get accurate results is to do a 2-point calibration to get the incline of the curve. to do a 2-point calibration, select 2 temperatures where you can do the measurements where the temperature is kn own and is accurate. do a measurement at both temperatures with the wanted setup of the adc (mode, sample rate,
12 AVR1300 8032h-avr-12/10 resolution). when you have these values, you can calculate the coefficient for the curve and you can use this in you application. the formula below can be used to calculate the temperature change per bit: valuelow valuehigh templow temphigh bittemp ? ? = / 3.5 conversion result 3.5.1 signed mode in signe d mode the conversion result from the adc is: topgain v vv res ref inn inp ** ? = v inp is the positive input and v inn is the negative input to t he adc. gain corresponds to the gain setting used. gain is 1 if gain is not used. top is the top value given by the configured resolution, which is 2048 for 12 bit mode and 128 for 8 bit mode. in signed mode the result is returned as a signed number represented on a two's complement format where the msb represen ts the sign bit. in 12-bit right adjusted mode, the sign bit (bit 11) is padded to bits 12-15 to create a signed 16-bit number directly. in 8-bit mode, the sign bit (bit 7) is padded to the entire high byte. with 12-bit resolution the range from ?v ref to +v ref will be -2048 to +2047 (0xf800 - 0x07ff). 3.5.2 unsigned mode in unsig ned mode the conversion result from the adc is: top v vv res ref inp * + = v inp is the single ended input and v = v ref x 0.05. top is the top value given by the configured resolution. for 12 bit mode top is 4096 and 8 bit mode top is 256. the positive offset given by v is typically 0.05*v ref . this typically corresponds to a measurement result of approximately 200 w hen the input pin is connected to ground. in order to measure this offset accurately the adc should be configured as it will be used in the application (i.e. voltages, speed and other settings) and the input pin should be connected externally to ground. this offset is not compensated for automat ically, and the software needs to subtract the measured offset from the conversion results. with 12-bit resolution the range from gnd to vref ? v will be from approximately 200 to +4095 (0x00c8 - 0x0fff).
AVR1300 13 8032h-avr-12/10 3.6 result presentation the adc can be configured to present conversion results in the following formats: ? 12 bits, right adjusted ? 8 bits, right adjusted ? 12 bits, left adjusted note that a lower resolution gives faster c onversions, as there are fewer pipeline stages for the signal samples to propagate through. therefore, selecting result presentation is a tradeoff between resolution and conversion speed. the adc resolution is configured using the conversion result resolution bit field ( resolution ) in control register b ( ctrlb ). the result will be stored in the result registers for each channel. the channels have separate flags to indicate when a new conversion is ready. if the result is not read before a new conversion is done, the current result will be lost. the dma can be set up to transfer the result from the result register into the sram when a new conversion is ready. this can be done for all channels when doing sweep and store all channels in one burst. 3.7 voltage references the application can choose between the following voltage references (v ref ) for conversion results: ? int1v - internal reference of 1.0 v ? intvcc - internal reference of v cc / 1.6 v ? arefa - external reference pin on porta ? arefb - external reference pin on portb ? av cc /2 ? internal reference of avcc/2 for xmega d devices the internal int1v reference is a 1.00v reference from the bandgap of the device. the bandgap voltage is 1.10v and the reference voltage is 10/11 of the bandgap voltage, giving the 1.00v reference. the ac curacy of the reference is dependent on the bandgap. the accuracy of the bandgap is stated in the device?s datasheet. the intvcc is a reference voltage based on v cc divided by 1.6. the accuracy is depending on the accuracy and stabilit y of the analog supply voltage (av cc ) and filtering should be used if the av cc is connected to the digital v cc . note that the external reference pin arefa/b is shared with the dac module. the voltage reference is configured using the reference selection bitfield ( refsel ) in the reference control register ( refctrl ). the external reference is located at pin 0 on porta and portb (arefa and arefb). note that for the external references the maximum voltage to be used is vcc ? 0.6v and the minimum voltage is 1v. the accuracy of the external reference is depending on the external circuitry and this has to be designed to satisfy the required accuracy for the adc measurements.
14 AVR1300 8032h-avr-12/10 3.8 conversion speed the adc clock is derived from a prescaled version of the atmel ? avr ? xmega ? peripheral clock, where the available factor s are 1/4, 1/8, 1/16, 1/32, 1/64, 1/128, 1/256 and 1/512. the adc clock has to be set within the minimum and maximum recommended speed for the adc module to guarantee correct operation. the adc clock is configured using the clock prescaler register ( prescaler ). having a fast adc clock gives a short propag ation time for each sample, but does not mean that you cannot sample a signal at a much slower rate. for instance, an application could sample at a rate of 10 khz even if the adc clock is 2 mhz. however, it is not possible to sample at a rate higher than one fourth of the system clock speed since the maximum adc clock is 1/4 th of the peripheral clock. for xmega a devices the adc clock should not be set higher than 2 mhz, for xmega d devices the top frequency limit is 1.4 mhz. lowest adc clock frequency for both xmega a and xmega d devices are 100 khz. see device datasheet for more information. the conversion rate must satisfy the require ments for the given source impedance. if the sampling rate is too high compared to the source impedance, the results will not be accurate. it?s important that you do not sample faster than the inclination rate of the signal to follow. the maximum sample rate is defined by the formula: )2ln() (2 1 1 + ??+? the values for c sample and r channel (r channel = r channel + r switch ) can be found in the datasheet for the device. the n represent the number of bi ts in the conversion and can be 8 or 12. the r source is the impedance of the analog signal source which can be calculated from the circuitry or found in t he datasheet of the devic e if using integrated sensors. to give an illustration of how this will af fect the sampling rate, we will use worst case numbers for r channel , r source and c sample . this is 4.5k ? for r channel + r switch and 5pf for c sample . this will give the relationship between source impedance and the maximum sampling rate as shown in figure 3-9 page 15.
AVR1300 15 8032h-avr-12/10 figure 3-9. sampling rate vs. source impedance (log/log plot) 3.9 free-running mode instead of manually starting conversi ons by setting one or more of the start conversion bits ( chnstart ) in control register a ( ctrla ) or assigning events to virtual channels, the adc can be put in fr ee-running mode. this means that a number of channels are repeatedly converted in sequence as long as the mode is active. the channel sweep selection bitfield ( sweep ) in the event control register ( evctrl ) selects which channels to include in free-running mode. you can choose between channel 0 only, channel 0 and 1, channel 0 to 2 or all four channels. note that the same bits are used to select the channels to include in an event- triggered conversion sweep, but that is out side the scope of this application note. care should be taken not to change any involved mux settings when in free-running mode, as this would corrupt conversion results. 3.10 interrupts to avoid having to poll a register to chec k when conversions are finished, the adc can be configured to issue interrupt requests upon conversion complete. this can be used to do result processing using inte rrupt handler code while leaving the cpu ready for other tasks most of the time. for more information, please refer to t he device datasheet or the application note ?avr1305: getting started with the xmega interrupt controller?.
16 AVR1300 8032h-avr-12/10 3.11 result comparator interrupt instead of merely converting an input val ue, the adc can be configured to compare the result to a given value and only issue an interrupt or event when the result is above or below that value. interrupts on compare match (above/below) can be configured individually on each channel, but the compare register is shared between all four virtual channels. typical use of this feature is to leav e one or more adc channels in free-running mode and configure the adc to issue an interrupt when one of the input signals reach a certain threshold. 3.12 calibration the adc module has been calibrated during pr oduction of the device. this calibration value is stored in the production signatur e row of the device. the calibration value compensates for mismatch between the individual steps of the adc pipeline and it improves the linearity of the adc. the calibration value is not loaded automatically, and should always be loaded from the production signature row ( adcxcal0/1 ) and written to the corresponding adc calibration registers ( call/calh ) before enabling the adc. flowcharts for loading stored calibration settings are shown in figure 2-9 below. figure 3-10. usi ng stored calibration settings write calibration registers using stored values enable adc by setting the adcen bit configure adc stored calibration adc ready the calibration value is factory calibr ated with high accuracy equipment to the datasheet accuracy, and is not intended for user calibration. the application note ?avr120: adc characte ristics and calibration? contains more information on characteristics of adcs and how to compensate for gain and offset errors.
AVR1300 17 8032h-avr-12/10 3.12.1 offset error the offset e rror is defined as the deviation of the actual adc?s transfer function from the ideal straight line at zero input voltage. when the transition from output value 0 to 1 does not occur at an input value of ? lsb, then we say that there is an offset erro r. with positive offset errors, the output value is larger than 0 when the input voltage approaches ? lsb from below. with negative offset errors, the input value is larg er than ? lsb when the first output value transition occurs. in other words, if the act ual transfer function lies below the ideal line, there is a negative offset and vice vers a. negative and positive offsets are shown in figure 3-11. figure 3-11. examples of positive (a) and negative (b) offset errors analog input output value analog input output value (a) (b) +1? lsb offset -2 lsb offset since single-ended conversion gives positive results only, the offset measurement procedures are different when using single-ended and differential channels. 3.12.2 offset error ? single-ended channels to me asure the offset error, increase the input voltage from gnd until the first transition in the output value occurs. ca lculate the difference between the input voltage for which the perfect adc would have shown the same transition and the input voltage corresponding to the actual transition. this difference, converted to lsb, equals the offset error. in figure 3-12a, the first transition occurs at 1 lsb. the transition is from 2 to 3, which equals an input voltage of 2? lsb for the perfect adc. the difference is +1? lsb, which equals the offset error. the doubl e-headed arrows show the differences. the same procedure applies to figure 3-12b. the first transition occurs at 2 lsb. the transition is from 0 to 1, which equals an input voltage of ? lsb for the perfect adc. the difference is -1? lsb, which equals the offset error.
18 AVR1300 8032h-avr-12/10 figure 3-12. positive (a) and negative (b ) offset errors in single-ended mode analog input (b) output value analog input (a) output value -1? lsb offset +1? lsb offset to compensate for offset errors when using single ended channels, subtract the offset error from every measured value. be aw are that offset errors limit the available range for the adc. a large positive offset e rror causes the output value to saturate at maximum before the input voltage reaches maximum. a large negative offset error gives output value 0 for the smallest input voltages. 3.12.3 offset error - differential channels with differe ntial channels, the offset measurement can be performed much easier since no external input voltage is required. the two differential inputs can be connected to the same voltage internally and the resulting output value is then the offset error. since this method gives no ex act information on where the first transition occurs, it gives an error of ? to 1 lsb (worst case). to compensate for offset errors when using differential channels, subtract the offset error from every measured value. in signed mode compensating for offset error caused by temperature, v cc or reference drift can easily be done using two channels. e.g. set the adc channel 0 muxpos to adc pin 0 and muxneg to adc pin 1. with channel 1 you do the opposite, set muxpos to adc pin 1 and muxneg to adc pin 0. channel 0 should give you a positive value and channel 1 should give you a negative value. from these values you should get a real-time offset compensated result by applying this formula: (ch0 + ch1*-1)/2. 3.12.4 gain error the g ain error is defined as the deviation of the last output st ep?s midpoint from the ideal straight line, after compensating for offset error. after compensating for offset errors, applying an input voltage of 0 always give an output value of 0. however, gain errors c ause the actual transfer function slope to deviate from the ideal slope. this gain error can be measured and compensated for by scaling the output values. run-time compensation often uses integer ar ithmetic, since floating point calculation takes too long to perform. therefore, to get the best possible precision, the slope deviation should be measured as far from 0 as possible. the larger the values, the better precision you get. this is descri bed in detail later in this document.
AVR1300 19 8032h-avr-12/10 the example of a 3-bit adc transfer functions with gain errors is shown in figure 3-13. the following description holds for both single-ended and differential modes. figure 3-13. examples of positive (a ) and negative (b) gain errors 000 001 010 011 100 101 110 111 0/8 1/8 2/8 3/8 4/8 5/8 6/8 7/8 aref analog input (a) output code 000 001 010 011 100 101 110 111 0/8 1/8 2/8 3/8 4/8 5/8 6/8 7/8 aref analog input (b) output code +1? lsb error -1? lsb error to measure the gain error, the input value is increased from 0 until the last output step is reached. the scaling factor for gain compensation equals the ideal output value for the midpoint of the last step di vided by the actual value of the step. 3.12.5 non-linearity whe n offset and gain errors are compensated for, the actual transfer function should be equal to the transfer function of perfec t adc. however, non-linearity in the adc may cause the actual curve to deviate slight ly from the perfect curve, even if the two curves are equal around 0 and at the point where the gain error was measured. there are two methods for measuring non-linear ity, both described below. figure 3-14 shows examples of both measurements. figure 3-14. example of a non- linear adc conversion curve 000 001 010 011 100 101 110 111 0/81/82/83/84/85/86/87/8aref analog input (a) output code 000 001 010 011 100 101 110 111 0/81/82/83/84/85/86/87/8aref analog input (b) output code ? lsb wide, dnl = -? lsb 1? lsb wide, dnl = +? lsb max inl = +? lsb 3.12.6 differential non-linearity differential non-linearity (dnl) is defined as the maximum and minimum difference between the step width and the perfect width (1 lsb) of any output step. non-linearity produces quantization steps wi th varying widths. all steps should be 1 lsb wide, but some are narrower or wider.
20 AVR1300 8032h-avr-12/10 to measure dnl, a ramp input voltage is applied and all output value transitions are recorded. the step lengths are found from t he distance between the transitions, and the most positive and negative deviations from 1 lsb are used to report the maximum and minimum dnl. 3.12.7 integral non-linearity integral non-linearity (inl) is defined as the maximum vertical difference between the actual and the perfect curve. inl can be interpreted as a sum of dnls . e.g. several consecutive negative dnls raise the actual curve above the perfect curve as shown in figure 3-14. negative inls indicate that the actual cu rve is below the perfect curve. the maximum and minimum inl are measured using the same ramp input voltage as in dnl measurement. record the deviati on at each conversion step midpoint and report the most positive and negative de viations as maximum and minimum inl. 3.12.8 measurements and compensation it is importan t that dnl and inl values are measured after offset and gain error compensation. if not, the results will be infe cted by the offset and gain error and thus not reveal the true dnl and inl. non-linearity cannot be compensated for with simple calculations. polynomial approximations or table lookups can be used for that purpose. however, the typical dnl and inl values are less than 2 lsb fo r the 12-bit adc of the xmega, and are rarely of any concern in real life applications. 3.12.9 decoupling to get stable results, we need decoupling. this is needed both for the analog signals measured and for t he reference used. to be able to have a common reference for all signals measured over time, the voltage reference has to be exactly the same . to achieve this, the reference has to be decoupled with a large capacitor. for internal references this is not directly possible, but the a vcc and v cc have to be decoupled sufficiently. for both a vcc and for the external references decoupling and filtering should be done. using a filter inductor and a large capacitor will help on keeping the reference stable. the larger the capacitor, the better st ability is achieved. a 1uf or larger capacitor is recommended. when using the adc you have to wait until the capacitor is fully charged and stable, before measurements can be done. the time until stable have to be calculated from the rise time of the rc connection of the capacitor. for the analog signals, decoupling should also be done. when having single ended signals, the decoupling should be done between the signal and ground and for differential signals the decoupling has to be between the positive and negative input. decoupling of the signals is a more complex situation than the reference and this has to take the signals into account. if the signals are switching fast, the decoupling capacitor has to be lower. the decoupling capacitor should be as high as possible without changing the rise and fall time of the signal. it is therefore hard to give an exact value for the decoupling, and this has to be calculated as an rc circuit.
AVR1300 21 8032h-avr-12/10 3.12.10 source impedance this i s a very common problem when doing adc designs. the source impedance is the sources capability to deliv er charge to the internal sampling capacitor fast enough. if the internal capacitor is not charged to the same level as the analog signal, the result will be wrong. when using a direct connection from a sensor ic, the impedance is usually stated in the datasheet of the device and it is ea sy to adjust the speed for the given impedance. when the circuitry is made up by passive components, calculations have to be done to find the actual source impedance. for ex ample, a resistor ladder dividing a high voltage down to a voltage that can be handl ed by the microcontroller can have very high impedance as large resistors are used to get the voltage sufficiently down. the solution is then to either lower the sample rate to be able to measure the correct signal or to lower the resistance value. lowering the resistance would cause more leakage current and this can again be solved by adding switching fet to enable and disable the analogue source. an example of this can be seen in the schematic below. another thing to be aware of in such an application is the time for the source to be stable, as the decoupling will take some time to charge to the correct level after enabling the analog source.
22 AVR1300 8032h-avr-12/10 3.13 tips for improving accuracy the accuracy of the atmel ? avr ? xmega ? adc depends on the quality of the input signals and power supplies. the following items should be taken into consideration for best possible accuracy of the adc measurements: ? understand the adc, its features and how they are intended used. ? understand the applications requirements. ? make sure the source impedance is not too high compared to the sampling rate that is used. if the source impedance is too high, the internal sampling capacitor will not be charged to the correct level and the result will not be accurate. ? it is important to take great care when designing the analog signal paths like analog reference (v ref ) and analog power supply (a vcc ). filtering should be used if the analog power supply is conn ected to the digital power supply. ? avoid having the analog signal path close to digital signal path with high switching noise (i.e. communication lines, clock signals). ? consider decoupling of the analog signal. decoupling between signal and ground for single ended inputs and decoup ling between the differential signal pair for differential measurements. ? try to toggle as few pins as possible while the adc is converting to avoid switching noise internally and on power supply. the adc is most sensitive to switching the i/o pins that are powered by the analog power supply (porta/portb). ? switch off unused peripherals by se tting prr registers to eliminate noise from unused peripherals. ? put the xmega in the ?idle? sleep mode directly after starting the adc conversion to reduce noise from the cpu. ? load the calibration values from the sig nature row into the calibration register in the adc. ? use the lowest gain possible to avoid amplifying external noise. ? wait until the adc, reference or so urces are stabilized before sampling as some sources (e.g. bandgap) need time to stabilize after they are enabled. ? apply offset and gain calibration to the measurement. ? use over-sampling to increase reso lution and eliminate random noise. ? jtag debugging interface create a lot of noise and should not be used while debugging an adc application. ? on the stk600 starter kit the decoupling capacitors are far from the actual unit. for randomly distributed noise using over sampling will help reducing any noise and improve accuracy. using 8x oversampling w ill increase resolution by 2 bits, and due to the pipelined design of the adc only take 8 additional adc clock cycles. see application note ?avr121: enhancing adc resolution by oversampling? for more information on oversampling.
AVR1300 23 8032h-avr-12/10 4 getting started this section walks you through the basic st eps for getting up and running with simple conversion and experimenting with mux settings. the necessary registers are described along with relevant bit settings. note that this section only covers manual polling of status bits. interrupt control is not covered, but is an easy step after studyi ng the application note ?avr1305: getting started with the atmel ? avr ? xmega ? interrupt controller?. 4.1 single conversion task: one single-ended conversion of a dc input 1 using virtual channel 2. ? set the input mode bitfield ( inputmode ) in channel 2 control register ( ch2ctrl ) equal to 0x01 to select single-ended input. ? set the mux positive input bitfield ( muxpos ) in channel 2 mux control register ( ch2muxctrl ) equal to 0x01 to select adc input 1. ? set the enable bit ( enable ) in control register a ( ctrla ) to enable the adc module without calibrating. wait for the adc start-up time (typ. max 24 adc clocks). ? set the start conversion bit for channel 2 ( ch2start ) in control register a ( ctrla ) to start a single conversion. ? wait for the interrupt flag bit for channel 2 ( ch2if ) in the interrupt flags register ( intflags ) to be set, indicating that the conversion is finished. ? read the result register pair for channel 2 ( ch2resl / ch2resh ) to get the 12-bit conversion result as a 2-byte value. 4.2 multiple channels task: one single-ended conver sion of adc input 3 and 6 using virtual channel 1 and 3. ? set the input mode bitfield ( inputmode ) in channel 1 control register ( ch1ctrl ) and channel 3 control register ( ch3ctrl ) equal to 0x01 to select single-ended input on both channels. ? set the mux positive input bitfield ( muxpos ) in the mux control register for channel 1 and 3 ( ch1muxctrl and ch3muxctrl ) equal to 0x03 and 0x06 respectively. ? set the enable bit ( enable ) in control register a ( ctrla ) to enable the adc module without calibrating. wait for the adc start-up time (typ. max 24 adc clocks). ? set the start conversion bit for channel 1 and 3 ( ch1start and ch3start ) in control register a ( ctrla ) to start two conversions. ? wait for the interrupt flag bits for channel 1 and 3 ( ch1if and ch3if) in the interrupt flags register ( intflags ) to be set, indicating that the conversions are finished. ? read the result register pair for channel 1 and 3 ( ch1resl / ch1resh and ch3resl / ch3resh ) to get the 12-bit conversion results as 2-byte values.
24 AVR1300 8032h-avr-12/10 4.3 free-running mode task: free-running differential conversion on channel 0, using adc0 and adc3 as positive and negative inputs. ? set the mux positive input and mux negative input bitfields ( muxpos and muxneg ) in channel 0 ( ch0muxctrl ) to 0x00 and 0x03 respectively. ? set the free run bit ( freerun ) in control register b ( ctrlb ) to enable free running mode. ? set the enable bit ( enable ) in control register a ( ctrla ) to enable the adc module without calibrating. wait for the adc start-up time (typ. max 24 adc clocks). ? optionally wait for the interrupt flag bit for channel 0 ( ch0if) in the interrupt flags register ( intflags ) to be set, indicating that a new conversion is finished. clear the flag by writing a one to it, as it is going to be used later. ? read the result register pair for channel 0 ( ch0resl / ch0resh ) to retrieve the latest 12-bit conversion resu lts as a 2-byte value. note that it is not strictly required to wa it for the interrupt flag when using free-running mode. however, to make sure you have a fresh conversion, you should wait for the flag, clear it and then read the result. also note that it is recommended to use the free-running mode together with dma data transfer to offload work from the cpu. 5 advanced features this section introduces more advanced features and possi bilities with the adc. in- depth treatment is outside the scope of this application note and the user is advised to study the device datasheet and relevant application notes. 5.1 dma controller instead of using interrupt handlers to read a nd process the result registers, it is possible to use the atmel ? avr ? xmega ? dma controller to move data from one or more result registers to memory buffers or other peripheral modules. this moving of data is done without cpu intervention, and leaves the cpu ready for other tasks, even without having to execute interrupt handlers. for more information, please refer to t he device datasheet or the application note ?avr1304: getting started with the xmega dma controller?. 5.2 event system to improve conversion timing and further offload work from the cpu, the adc is connected to the xmega event system. this makes it possible to use incoming events to trigger single conversions or conversion sweeps across several channels. the adc conversion complete conditions also serve as event sources available for other peripheral modules c onnected to the event system. for more information, please refer to t he device datasheet or the application note ?avr1001: getting started with the xmega event system?.
AVR1300 25 8032h-avr-12/10 6 driver implementation this application note includes a source code package based on asf 2.0 (application software framework). the source code is compatible with avr studio ? . note that this adc driver is not intended for use with high-performance code. it is designed as a library to get started with the adc. for timing and code space critical application development, you should access th e adc registers directly. please refer to the driver source code and device datasheet for more details. 6.1 files for a complete overview of the available driver interface functions and their use, please refer to the source code documentation. 6.2 doxygen documentation all source code is prepared for automatic documentation generation using doxygen. doxygen is a tool for generating document ation from source code by analyzing the source code and using special keywords. for more details about doxygen please visit u http://www.doxygen.org h . precompiled doxygen documentation is also supplied with the source code accompanying this application note, available from the readme.html file in the source code folder.
8032h-avr-12/10 atmel corporation 2325 orchard parkway san jose, ca 95131 usa tel: (+1)(408) 441-0311 fax: (+1)(408) 487-2600 www.atmel.com atmel asia limited unit 01-5 & 16, 19f bea tower, milennium city 5 418 kwun tong road kwun tong, kowloon hong kong tel: (+852) 2245-6100 fax: (+852) 2722-1369 atmel munich gmbh business campus parkring 4 d-85748 garching b. munich germany tel: (+49) 89-31970-0 fax: (+49) 89-3194621 atmel japan 9f, tonetsu shinkawa bldg. 1-24-8 shinkawa chou-ku, tokyo 104-0033 japan tel: (+81) 3523-3551 fax: (+81) 3523-7581 ? 2010 atmel corporation. all rights reserved . / rev.: corp0xxxx atmel ? , atmel logo and combinations thereof, avr ? , avr ? logo, xmega ? , avr studio ? , and others, are the registered trademarks or trademarks of atmel corporation or its subsidiaries. ot her terms and product names may be trademarks of others. disclaimer: the information in this document is provi ded in connection with atmel products. no li cense, express or im plied, by estoppel or otherwise, to any intellectual property right is granted by this docum ent or in connection with the sale of atmel products. except as set forth in the atmel terms and conditions of sales located on the atmel website, atmel assumes no liability whatsoever and disclaims any express, implied or statut ory warranty relating to its products including, but no t limited to, the implied warranty of merchantability, fitness for a particular purp ose, or non-infringement. in no event shall atmel be liable for any direct, indirect, consequential, punitive, special or incide ntal damages (including, without limitation, damages for loss and profits, business interruption, or loss of information) arising out of the use or inability to use this document, even if at mel has been advised of the possibility of such damages. atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and rese rves the right to make changes to specifications and product descriptions at any time without notice. atmel does not make any commitment to update the information contained herein. unless specifically provided otherwise, atmel products are not suitable for, and s hall not be used in, automotive applications. atmel products are not intended, authorized, or warranted for use as components in applicat ions intended to support or sustain life.


▲Up To Search▲   

 
Price & Availability of AVR1300

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X